package com.lifl.b328.garden.model;

import android.content.ContentValues;
import android.database.Cursor;

public class NoteLocDistDAO extends CacheDAO<CoupleLocalDistant>{

	@Override
	public long add(CoupleLocalDistant obj) {
		ContentValues values = new ContentValues();
		values.put(Constantes.KEY_POOL_NOTE_LOCALE, obj.getLocal());
		values.put(Constantes.KEY_POOL_NOTE_DISTANTE, obj.getDistant());
		System.out.println(Constantes.KEY_POOL_NOTE_DISTANTE +" ="+ obj.getDistant());
		System.out.println(Constantes.KEY_POOL_NOTE_LOCALE+" ="+obj.getLocal());
		long row = db.insert(Constantes.TABLE_POOL_NOTE, null, values);
		MonLog.print("insertion note Loc(" +obj.getLocal()+ ") Dist("+obj.getDistant()+") "+row, this.getClass());
		return row;
	}

	@Override
	public long delete(long rowid) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public long edit(CoupleLocalDistant obj, long rowid) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public CoupleLocalDistant getByColumn(String column,Object valeur) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public CoupleLocalDistant getById(long id) {
		ContentValues values = new ContentValues();
		values.put(Constantes.KEY_POOL_NOTE_DISTANTE, id);
		MonLog.print(Constantes.KEY_POOL_NOTE_DISTANTE +" = "+id,getClass());
		Cursor cursor = db.query(Constantes.TABLE_POOL_NOTE, null, Constantes.KEY_POOL_NOTE_DISTANTE +" = ?",new String[]{ (id+"")},
				null, null, null);
		MonLog.print(cursor.getCount()+" cursor count",getClass());
		
		if(cursor == null || cursor.getCount() <= 0){
			return new CoupleLocalDistant(-1, id);
		}

		cursor.moveToFirst();
		long local = cursor.getLong(cursor.getColumnIndex(Constantes.KEY_POOL_NOTE_LOCALE));
		long distant = cursor.getLong(cursor.getColumnIndex(Constantes.KEY_POOL_NOTE_DISTANTE));
		MonLog.print("local "+local+ " distant "+distant,getClass());
		return new CoupleLocalDistant(local,distant);		
		
	}

	@Override
	public Cursor getAll(long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Cursor getAll(long id, String order) {
		// TODO Auto-generated method stub
		return null;
	}

	
}
